<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('页面列表')" />
    <style type="text/css">
        .img-circle2 {
            border-radius: 50%;
        }
        .img {
            cursor:pointer;
        }
        body .bootstrap-tree-table .treetable-tbody td {
            border: 0 !important;
            border-left: 0px solid #e7eaec !important;
            border-bottom: 1px solid #e7eaec!important;
            white-space: break-spaces !important;
            text-overflow: ellipsis;
            word-wrap: break-word;
        }
        body .bootstrap-tree-table .treetable-tbody td a{
            margin-top: 2px !important;
        }
    </style>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>页面名称：</label>
                                <input type="text" name="pageName" id="pageName"/>
                            </li>
                            <li>
                                <label>是否模块聚合页：</label>
                                <select name="isModuleAggregation" id="isModuleAggregation" th:with="type=${@dict.getType('sys_yes_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>是否风险点：</label>
                                <select name="isRask" id="isRask" th:with="type=${@dict.getType('sys_yes_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>终端类型：</label>
                                <select name="terminalType" id="terminalType" th:with="type=${@dict.getType('terminalType')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>分类名称：</label>
                                <div class="col-sm-3">
                                    <div class="input-group ">
                                        <input id="categoryCode" name="categoryCode" type="hidden"/>
                                        <input class="form-control" type="text" onclick="selectCategoryTree()" id="categoryName" readonly="true">
                                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                                    </div>
                                </div>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="page:page:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="page:page:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-info" id="expandAllBtn">
                    <i class="fa fa-exchange"></i> 展开/折叠
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-tree-table" style="word-break:break-all; word-wrap:break-all;"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var addFlag = [[${@permission.hasPermi('page:page:add')}]];
        var editFlag = [[${@permission.hasPermi('page:page:edit')}]];
        var removeFlag = [[${@permission.hasPermi('page:page:remove')}]];
        var isModuleAggregationDatas = [[${@dict.getType('sys_yes_no')}]];
        var isRaskDatas = [[${@dict.getType('sys_yes_no')}]];
        var terminalTypeDatas = [[${@dict.getType('terminalType')}]];
        var prefix = ctx + "page/page";
        var categoryCode = $("#categoryCode").val();
        var categoryName = $("#categoryName").val();
        function reset() {
            $.form.reset(null, null, null, null, true);
            $("#categoryCode").val(categoryCode);
            $("#categoryName").val(categoryName);
        }
        var prefix2 = ctx + "category/category"
        /*分类体系-新增-选择父分类体系树*/
        function selectCategoryTree() {
            var options = {
                title: '分类体系选择',
                width: "380",
                url: prefix2 + "/selectCategoryTree2/0/2",
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        $("body").on('click', ".img", function(e) {
            if(e.preventDefault){
                e.preventDefault();
            }else{
                window.event.returnValue == false;
            }
            var url = $(this).attr("src");
            var json = {
                "title": "预览",
                "start": 0,
                "data": [{
                    "src": url,
                }]
            };
            layer.photos({
                photos: json,
                closeBtn: 0, //右上角按钮，可通过配置1和2来展示，如果不显示，则closeBtn: 0
                anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
            });
        });

        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
            $("#categoryCode").val(body.find('#treeCode').val());
            $("#categoryName").val(body.find('#treeName').val());
            layer.close(index);

            $.treeTable.search();
        }

        $(function() {
            var options = {
                code: "id",
                parentCode: "parentId",
                expandColumn: "1",
                uniqueId: "id",
                url: prefix + "/list",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove/{id}",
                exportUrl: prefix + "/export",
                expandAll: false,
                expandFirst: false,
                ajaxParams : {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    pageName: $("#pageName").val(),
                    isModuleAggregation: $("#isModuleAggregation").val(),
                    terminalType: $("#terminalType").val(),
                    categoryCode: $("#categoryCode").val(),
                    isRask: $("#isRask").val()
                },
                modalName: "页面",
                columns: [{
                    field: 'selectItem',
                    radio: true
                },
                {
                    field: 'pageName',
                    title: '页面名称',
                    align: 'left',
                    width: '20',
                    widthUnit: '%'
                },
                // {
                //     field: 'pageDescription',
                //     title: '页面描述',
                //     align: 'left',
                //     width: '20',
                //     widthUnit: '%'
                // },
                // {
                //     field: 'isModuleAggregation',
                //     title: '是否模块聚合页',
                //     align: 'left',
                //     width: '15',
                //     widthUnit: '%',
                //     formatter: function(value, row, index) {
                //         return $.table.selectDictLabel(isModuleAggregationDatas, value);
                //     }
                // },
                // {
                //     field: 'isRask',
                //     title: '是否风险点',
                //     align: 'left',
                //     formatter: function(value, row, index) {
                //         return $.table.selectDictLabel(isRaskDatas, value);
                //     },
                //     width: '15',
                //     widthUnit: '%'
                // },
                // {
                //     field: 'terminalType',
                //     title: '终端类型',
                //     align: 'left',
                //     formatter: function(value, row, index) {
                //         return $.table.selectDictLabel(terminalTypeDatas, value);
                //     },
                //     width: '10',
                //     widthUnit: '%'
                // },
                {
                    field: 'categoryName',
                    title: '分类名称',
                    align: 'left',
                    width: '10',
                    widthUnit: '%'
                },
                    {
                        field: 'categoryName',
                        title: '图片',
                        align: 'left',
                        formatter: function(value, row, index) {
                            var html = "";
                            if (row.fileInfList && row.fileInfList.length > 0) {
                                for (var i=0; i<row.fileInfList.length; i++) {
                                    html = html + "<span class='img' title='"+row.fileInfList[i].fileName+"' data='"+row.fileInfList[i].id+"' src='"+row.fileInfList[i].filePath+"'>图"+(i+1)+"</span>&nbsp;";
                                }
                            }
                            return html;
                        },
                        width: '30',
                        widthUnit: '%'
                    },
                    {
                        field: 'categoryName',
                        title: '组件图片',
                        align: 'left',
                        formatter: function(value, row, index) {
                            var html = "";
                            if (row.componentFileInfList && row.componentFileInfList.length > 0) {
                                for (var i=0; i<row.componentFileInfList.length; i++) {
                                    html = html + "<span class='img' title='"+row.componentFileInfList[i].fileName+"' data='"+row.componentFileInfList[i].id+"' src='"+row.componentFileInfList[i].filePath+"'>图"+(i+1)+"</span>&nbsp;"
                                }
                            }
                            return html;
                        },
                        width: '30',
                        widthUnit: '%'
                    },
                {
                    title: '操作',
                    align: 'center',
                    align: 'left',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="uploadImg(\'' + row.id + '\', 1)"><i class="fa fa-edit"></i>上传图片</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="uploadImg(\'' + row.id + '\', 2)"><i class="fa fa-edit"></i>上传组件图</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="deleteImg(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除图片</a> ');
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="detail(\'' + row.id + '\')"><i class="fa fa-search"></i>详情</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.id + '\')"><i class="fa fa-plus"></i>新增</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        //var more = [];
                        // actions.push("<a class='btn btn-default btn-xs' href='javascript:void(0)' onclick='tableList(" + row.id + ")'><i class='fa fa-user'></i>关联表</a> ");
                        // actions.push("<a class='btn btn-default btn-xs' href='javascript:void(0)' onclick='usageList(" + row.id + ")'><i class='fa fa-user'></i>关联用况</a>");
                        //actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
                        return actions.join('');
                    },
                    width: '30',
                    widthUnit: '%'
                }]
            };
            $.treeTable.init(options);
        });

        function uploadImg(id, type) {
            var title = "上传图片";
            var url = prefix + "/add_img/" + id+ "/" + type;
            var width = 800;
            var height = $(window).height() - 50;
            $.modal.open(title, url, width, height);
        }

        function deleteImg(id) {
            var url = prefix + "/deleteImg?id="+id;
            var width = $(window).width() - 50, height = $(window).height() - 50;
            layer.open({
                type: 2,
                area: [width + 'px', height + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "删除图片",
                content: url,
                btn: ['确定', '关闭'],
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    iframeWin.contentWindow.submitHandler(index, layero);
                },
                cancel: function(index) {
                    return true;
                }
            });
        }

        function tableList(id) {
            var options = {
                title: "关联表详细",
                width: $(window).width() - 50,
                height: $(window).height() - 50,
                url: prefix + "/tableList?id="+id,
                skin: 'layui-layer-gray',
                btn: ['关闭'],
                yes: function (index, layero) {
                    layer.close(index);
                }
            };
            $.modal.openOptions(options);
        }

        function usageList(id) {
            var options = {
                title: "关联用况详细",
                width: $(window).width() - 50,
                height: $(window).height() - 50,
                url: prefix + "/usageList?id="+id,
                skin: 'layui-layer-gray',
                btn: ['关闭'],
                yes: function (index, layero) {
                    layer.close(index);
                }
            };
            $.modal.openOptions(options);
        }

        function detail(id) {
            $.operate.addTab2("页面详情", prefix + "/detail/" + id);
        }
    </script>
</body>
</html>